/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.escritura;

import br.com.deployment.daogenerico.DaoGenerico;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.Query;

/**
 *
 * @author roniere
 */
@Stateless
@LocalBean
public class ImportEscritura extends DaoGenerico<EscrituraOld> implements importEscrituraIn {

    public ImportEscritura() {
        super(EscrituraOld.class);
    }

    @Override
    public List<EscrituraOld> findAll(String d1, String d2) {
        Query query = null;
        System.err.println(d1 + " --- "+d2);
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String sql = "select e from EscrituraOld e where "
                    + " e.tip <> '3' and e.tip <> '2' and e.tip <> '1' and e.tip <> '58'"
                    + " and e.tip <> '17' and e.dat <> ''"
                    + " and "
                    + " e.data BETWEEN :dateIni AND :dateFim";

            query = getEm().createQuery(sql);
            query.setParameter("dateIni", sdf.parse(d1));
            query.setParameter("dateFim", sdf.parse(d2));
            System.err.println(sql);
        } catch (ParseException ex) {
            Logger.getLogger(ImportEscritura.class.getName()).log(Level.SEVERE, null, ex);
        }
        return query.getResultList();

        //         return getEm().createQuery("select e from EscrituraOld e where e.data is null and e.dat <> ''").getResultList();

    }
}
